package top.lingchen.blogapi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.lingchen.blogapi.service.CommentsService;
import top.lingchen.blogapi.vo.Result;
import top.lingchen.blogapi.vo.params.CommentParam;

/**
 * @Author 凌宸
 * @create 2021-12-17 下午 2:44
 * @Description
 * @Version 1.0
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 根据文章 id 获取评论列表 /comments/article/{id}
     * @param articleId
     * @return
     */
    @GetMapping("/article/{id}")
    public Result getComments(@PathVariable("id") Long articleId){
        return commentsService.findCommentsByArticleId(articleId);
    }

    /**
     * 新增评论
     * @param commentParam
     * @return
     */
    @PostMapping("/create/change")
    public Result comment(@RequestBody CommentParam commentParam){
        return commentsService.comment(commentParam);
    }
}
